﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MS.BasicData.Infrastructure;
using MS.BasicData.Read.API.Applications.ProductInfos;
using MS.BasicData.Read.API.Applications.Products;

namespace MS.BasicData.Read.API.Controllers
{
    /// <summary>
    /// 商品控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProductController : ControllerBase
    {
        private readonly IMediator _mediator;

        public ProductController(IMediator mediator)
        {
            _mediator = mediator;
        }

        /// <summary>
        /// 添加商品信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiRestult> AddProduct(CreateProductInfoRequestModel command)
        {
           return  await _mediator.Send(command);
        }

        /// <summary>
        /// 获取商品列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiRestult> GetProductList()
        {
            ListProductInfoRequestModel command = new ListProductInfoRequestModel();
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 溯源商品新增
        /// </summary>
        /// <param name="add">溯源商品信息</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiRestult> CreateProduct(CreateProductRequestModel add)
        {
            return await _mediator.Send(add);
        }

        /// <summary>
        /// 获取溯源商品列表
        /// </summary>
        /// <param name="command">溯源信息列表</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiRestult> GetListProduct()
        {
            GetListProductRequestModel command = new GetListProductRequestModel();
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 溯源商品信息删除
        /// </summary>
        /// <param name="ProductId">溯源商品信息主键Id</param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<ApiRestult> DeleteProduct(int ProductId)
        {
            DeleteProductRequestModel command = new DeleteProductRequestModel() { ProductId = ProductId };
            return await _mediator.Send(command);
        }


    }
}
